<include file="__THEME__/public_header" />
<div class="content">
    <div class="wrap">
        <div class="con_side">
            <ul class="nav">
                <li><a href="{:U('admin/Resource/admin_show_resource')}">资源管理</a></li>
                <li  class="cursor"><a href="{:U('admin/Resource/teacher')}">教师管理</a></li>
            </ul>
        </div>
        <div class="con_main">
            <div class="con_tit">
                <ul class="con_link">
                    <li class="on"><a href="javascript:;">教师列表</a></li>
                    <li><a href="javascript:addUser();">新建老师</a></li>
                </ul>
            </div>
            <div class="con_tit">
                <table class="table table_title t5_3">
                  <tbody><tr>
                    <td>教师名称</td>
                    <td>操作</td>
                  </tr>
                </tbody></table>
            </div>
            <div class="con_box">
                <table class="table table_list t5_3">
                  <tbody>
                  <volist name="data" id="user">
                      <tr>
                        <td id="name{$user.id}">{$user.name}</td>
                        <td>
                            <a href="javascript:updateUser({$user.id});">修改</a>
                            <a href="javascript:delUser({$user.id});">删除</a>
                        </td>
                      </tr>
                  </volist>
                </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="pop_wrap" id="pop_wrap" style="display:none;">
  <div class="pop_box">
      <div class="pop_head"><a class="close" href="javascript:close();">X</a><span id="title"></span></div>
        <div class="pop_body">
          <dl class="diapei_dl">
              <dt>教师名称：</dt>
                <dd>
                   <input type="text" id="name">
                </dd>
            </dl>
        </div>
        <ul class="pop_foot">
          <li><a href="javascript:close();">取消</a></li>
          <li><a href="javascript:doUpdateUser();">确定</a></li>
        </ul>
    </div>
</div>
<input type="hidden" id="id">
<script>
  function delUser(id){
      if(confirm("你确定要删除该教师？")){
          $.ajax({
            type: "POST",
            url:"{:U('admin/Resource/DelTeacher')}",
            data:"id="+id,
            dataType:"text",
            success:function(data){
              if(isNaN(data)){
                alert(data);
              }else{  
                window.location.href=window.location.href;
              }
            }
          });
      }
  }
  function updateUser(id){
      $("#id").val(id);
      $("#title").append("修改教师");
      $("#name").val($("#name"+id).html());
      $("#pop_wrap").css("display","block");
  }
  function addUser(id){
      $("#id").val("");
      $("#title").append("添加教师");
      $("#name").val("");
      $("#pop_wrap").css("display","block");
  }
  function doUpdateUser(){
     var id=$("#id").val();
     var name=$("#name").val();
     if(name==""){
        alert("请输入教师名称");
        return;
     }
     $.ajax({
        type: "POST",
        url:"{:U('admin/Resource/doUpdateTeacher')}",
        data:"id="+id+"&name="+name,
        dataType:"text",
        success:function(data){
          if(isNaN(data)){
            alert(data);
          }else{  
            close();
            window.location.href=window.location.href;
          }
        }
      });
    }
    function close(){
        $("#id").val("");
        $("#name").val("");
        $("#pop_wrap").css("display","none");
    }
</script>
<include file="__THEME__/public_footer" />